package com.newdream.annotation.controller;

import com.alibaba.fastjson.JSON;
import com.newdream.annotation.model.User;
import com.newdream.annotation.service.UserService;
import com.newdream.annotation.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author: sanglei
 * @date: 2019-02-13 14:10
 * @description:
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    RedisUtil redisUtil;
    @PostMapping("findUser")
    public User getUser(@RequestParam(value = "id") Integer id){
        User user = userService.findUser(id);
        redisUtil.set("ss", JSON.toJSONString(user),30000);
        Object ss = redisUtil.get("ss");
        System.out.println(ss);
        return user;
    }
    @PostMapping("save")
    public User save(@RequestBody User user){
        user.setCreateTime(new Date());
        user.setUpdateTime(new Date());
        return userService.save(user);
    }
}
